package com.wyy.controller;

import com.wyy.pojo.AppreciatesOrder;
import com.wyy.pojo.UserPojo;
import com.wyy.response.CommonReturnType;
import com.wyy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: gytcb
 * @author: 吴磊
 * @create: 2021-06-30 19:20
 */
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 删除超时并未支付的订单
     *
     * @return
     */
    @RequestMapping(value = "/deleteTimeOutOrder", method = RequestMethod.POST)
    public CommonReturnType deleteTimeOutOrder() {
        orderService.deleteTimeOutOrder();
        return CommonReturnType.create(null);
    }


    /**
     * 获取所有的用户
     *
     * @param userPojo
     * @return
     */
    @RequestMapping(value = "/getAllOrder", method = RequestMethod.POST)
    public CommonReturnType getAllOrder(@RequestBody UserPojo userPojo) {
        Map<String, Object> allOrder = orderService.getAllOrder(userPojo);
        return CommonReturnType.create(allOrder);
    }

    /**
     * 根据ID删除订单
     *
     * @param appreciatesOrder
     * @return
     */
    @RequestMapping(value = "/deleteOrderById", method = RequestMethod.POST)
    public CommonReturnType deleteOrderById(@RequestBody AppreciatesOrder appreciatesOrder) {
        orderService.deleteOrderById(appreciatesOrder);
        return CommonReturnType.create(null);
    }
}
